/* lyric.js */
import { ipcMain } from 'electron'
import {
  LYRIC_WINDOW_MOVE,
  MUSIC_PLAYER_CANPLAY,
  MUSIC_PLAYER_LYRIC_ACTIVE,
  MUSIC_PLAYER_LYRIC_HIDE,
  MUSIC_PLAYER_LYRIC_LOCK,
  MUSIC_PLAYER_LYRIC_UNLOCK,
  MUSIC_PLAYER_PAUSE,
  MUSIC_PLAYER_PLAY,
  MUSIC_PLAYER_TIMEUPDATE
} from './channel'

/** 注册歌词事件到IpcMain */
export function registerLyricEvent2IpcMain(lyricWin) {
  ipcMain.on(MUSIC_PLAYER_CANPLAY, (event, res) => {
    lyricWin.webContents.send(MUSIC_PLAYER_CANPLAY, res)
  })
  ipcMain.on(MUSIC_PLAYER_PLAY, (event, res) => {
    lyricWin.webContents.send(MUSIC_PLAYER_PLAY, res)
  })
  ipcMain.on(MUSIC_PLAYER_PAUSE, (event, res) => {
    lyricWin.webContents.send(MUSIC_PLAYER_PAUSE, res)
  })
  ipcMain.on(MUSIC_PLAYER_TIMEUPDATE, (event, res) => {
    lyricWin.webContents.send(MUSIC_PLAYER_TIMEUPDATE, res)
  })
  ipcMain.on(MUSIC_PLAYER_LYRIC_ACTIVE, (event, res) => {
    lyricWin.show()
    lyricWin.webContents.send(MUSIC_PLAYER_LYRIC_ACTIVE, res)
  })
  ipcMain.on(MUSIC_PLAYER_LYRIC_HIDE, (event, res) => {
    lyricWin.hide()
    lyricWin.webContents.send(MUSIC_PLAYER_LYRIC_HIDE, res)
  })
  ipcMain.on(MUSIC_PLAYER_LYRIC_LOCK, (event, res) => {
    // 设置为可穿透
    lyricWin.setIgnoreMouseEvents(true, { forward: true })
  })
  ipcMain.on(MUSIC_PLAYER_LYRIC_UNLOCK, (event, res) => {
    lyricWin.setIgnoreMouseEvents(false)
  })
  ipcMain.on(LYRIC_WINDOW_MOVE, (event, { x, y }) => {
    lyricWin.setPosition(x, y)
  })

}
